package com.feng.financial.seller.service;

import com.feng.financial.api.event.ProductStatusEvent;
import com.feng.financial.api.service.ProductRpcService;
import com.feng.financial.api.to.QueryAllProductByPageReq;
import com.feng.financial.common.web.Range;
import com.feng.financial.entity.ProductEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * @author Administrator
 */
@Service
public class ProductService {

    public static final Logger LOGGER = LoggerFactory.getLogger(ProductService.class);

    static final String MQ_DESTINATION = "Consumer.cache.VirtualTopic.PRODUCT_STATUS";

    @Autowired
    private ProductRpcService productRpcService;

    public List<ProductEntity> findAllByPage(Range range){
        return productRpcService.queryAllProductByPage(new QueryAllProductByPageReq(range.getLength(), range.getStart()));
    }

    public ProductEntity findOne(String id) {
        return productRpcService.findOneProduct(id);
    }

//    @JmsListener(destination = MQ_DESTINATION)
//    public void updateProductStatus(ProductStatusEvent event){
//        LOGGER.info(event.toString());
//    }

    /*@PostConstruct
    private void main(){
        List<ProductEntity> allByPage = this.findAllByPage(new Range(0, 1000));
        LOGGER.info(allByPage.toString());
         LOGGER.info(this.findOne("1").toString());
    }*/
    
}
